//
//  choseRoleController.m
//  qianke
//
//  Created by ZX on 2017/7/17.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "choseRoleController.h"
#import "ZXSaleController.h"

@interface choseRoleController (){
    UILabel *lblDate;
}

@end

@implementation choseRoleController

- (void)viewDidLoad {
    my_AppDelegate.isLandscape = NO;
    [super viewDidLoad];
    [self creatSubviews];
}
- (void)creatSubviews{

    self.tabBarController.tabBar.hidden =YES;
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = baseBlueColor;
    [self.view addSubview:view];
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-100)/2, 30, 100, 34)];
    [label setText:@"选择角色"];
    [label setFont:[UIFont systemFontOfSize:17]];
    [label setTextColor:[UIColor whiteColor]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:label];
    UIButton * backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 30, 40, 34)];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(bacKRoot) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    self.navigationController.navigationItem.hidesBackButton = YES;
    lblDate = [UILabel createLabelWithAutoLayoutFont:[UIFont systemFontOfSize:15] textColor:baseBlueColor];
    lblDate.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lblDate];
    
    
    lblDate.sd_layout
    .leftEqualToView(self.view)
    .rightEqualToView(self.view)
    .topSpaceToView(self.view, 64)
    .heightIs(40);
    
    NSDate *nowDate = [NSDate date];
    
    NSString *week = [ZXToolObj weekdayStringFromDate:nowDate];
    
    NSString *strDate = [ZXToolObj getDateFromDay:nowDate];
    
    lblDate.text = [NSString stringWithFormat:@"%@  %@",strDate ,week];

    NSArray *aryTitle = @[@"销售顾问",@"售前店长/经理",@"售前督导/大区经理",@"售后店长/经理",@"售后督导/大区经理",@""];
    NSArray *aryTitleDetail = @[@"",@"横屏显示",@"横屏显示",@"横屏显示",@"横屏显示",@""];
    NSArray *aryImages = @[@"销售顾问",@"售前店长经理",@"售前督导大区经理",@"售后店长经理",@"售后督导大区经理",@""];
    for (int i = 0; i<aryTitle.count; i++) {
        UIButton *btn = [UIButton new];

        btn.tag = 100+i;
        [self.view addSubview:btn];
        [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        int row = i/2;
        int column = i%2;
        
        UILabel *lbl = [UILabel createLabelWithAutoLayoutFont:[UIFont systemFontOfSize:12] textColor:baseBlueColor];
        lbl.backgroundColor = ZXColor(225, 238, 254);
        lbl.textAlignment = NSTextAlignmentCenter;
        lbl.tag = 110+i;
        lbl.layer.cornerRadius = 10;
        lbl.clipsToBounds = YES;
        
    
        
        UILabel *lbl1 = [UILabel createLabelWithAutoLayoutFont:[UIFont systemFontOfSize:10] textColor:[UIColor grayColor]];
        lbl1.backgroundColor = baseBackgroundColor;
        lbl1.textAlignment = NSTextAlignmentCenter;
        lbl1.tag = 120+i;
        UIImage *img = [UIImage imageNamed:[aryImages objectAtIndex:i]];
        [btn setBackgroundImage:img forState:UIControlStateNormal];
        
        for (int j = 0; j<my_AppDelegate.roleArr.count; j++) {
            NSString * temStr = [NSString stringWithFormat:@"%@",my_AppDelegate.roleArr[j]];
//            NSLog(@"%d",temStr.intValue);
            if (i == temStr.intValue) {
                [btn setBackgroundImage:[UIImage imageNamed:@"灰色不可点击"] forState:UIControlStateNormal];
                [lbl setTextColor:baseGrayColor];
                [lbl1 setTextColor:baseGrayColor];
                btn.enabled = NO;
            }
        }
        
        if (i == aryTitle.count-1) {
            [btn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
            btn.enabled = NO;
        }
        UIImageView *imgvStar = [UIImageView new];
        
        UIImageView *imgvLine = [UIImageView new];
        imgvLine.backgroundColor = ZXColor(230, 230, 230);
        imgvLine.tag = 130+i;
        [self.view addSubview:lbl];
        [self.view addSubview:lbl1];
        [self.view addSubview:imgvStar];
        [self.view addSubview:imgvLine];
        if (i == aryTitle.count-1) {
            lbl.hidden = YES;
            lbl1.hidden = YES;
        }
        
        
        btn.sd_layout
        .leftSpaceToView(self.view,ScreenWidth*0.15 +0.504*ScreenWidth*column)
        .topSpaceToView (lblDate,0.03*ScreenHeight + 0.03 *ScreenHeight*row + (0.192*ScreenWidth+65)*row)
        .widthRatioToView(self.view ,0.192)
        .heightEqualToWidth(0);
        
        CGFloat titleWidth = [aryTitle[i] stringSizeWithMaxSize:CGSizeMake(ScreenWidth*0.45, 30) withFont:[UIFont systemFontOfSize:13]].width;
        lbl.sd_layout
        .centerXEqualToView(btn)
        .topSpaceToView(btn,10)
        .widthIs(titleWidth+ZXMargin)
        .heightIs(20);
        
        
        
        lbl1.sd_layout
        .centerXEqualToView(btn)
        .topSpaceToView(lbl,10)
        .widthIs(45)
        .heightIs(15);
        
        imgvStar.sd_layout
        .rightSpaceToView(lbl1,3)
        .centerYEqualToView(lbl1)
        .widthIs(9)
        .heightIs(9);
        
        
        if (i==0||i==5) {
            imgvStar.image = nil;
        }else{
            imgvStar.image = [UIImage imageNamed:@"Star"];
        }
        
        imgvLine.sd_layout
        .centerXEqualToView(btn)
        .topSpaceToView(lbl1,10)
        .widthIs(ScreenWidth*0.55)
        .heightIs(1.0);
        
        NSString *title = [aryTitle objectAtIndex:i];
        NSString *title1 = [aryTitleDetail objectAtIndex:i];
        
        lbl.text = title;
        lbl1.text = title1;
        
    }
    [self createCellLine];

}
-(void)bacKRoot{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"backToLogin" object:nil];
}
- (void)createCellLine{
    UIView *imgvTopLine = [UIView new];
    imgvTopLine.backgroundColor = ZXColor(230, 230, 230);
    [self.view addSubview:imgvTopLine];
    
    imgvTopLine.sd_layout
    .topSpaceToView(lblDate,0)
    .leftEqualToView(self.view)
    .rightEqualToView(self.view)
    .heightIs(1.0);
    
    UIView *imgvCenter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 2, 100)];
    imgvCenter.backgroundColor = ZXColor(230, 230, 230);
    [self.view addSubview:imgvCenter];
    
    UIView *imgvCelLine = [self.view viewWithTag:135];
    
    imgvCenter.sd_layout
    .topSpaceToView(lblDate,0)
    .centerXEqualToView(self.view)
    .widthIs(1)
    .bottomSpaceToView(imgvCelLine,0);
    
}
- (void)btnClicked:(UIButton *)btn{
    if (btn.tag == 100) {

        [self.navigationController popViewControllerAnimated:NO];
    }else{
        
        ZXSaleController * saleVc = [ZXSaleController new];
        saleVc.horizontalScreen = YES;
        if (btn.tag == 101){
            saleVc.leftTitle = @"销售顾问业绩";
            saleVc.rightTitle = @"店内账户信息";
            saleVc.headerViewType = 0;
            NSLog(@"4s店长");
            
        }else if (btn.tag == 102){
            saleVc.btnBigViewHidden = YES;
            saleVc.labelTitle = @"我是售前督导/大区经理";
            saleVc.headerViewType = 1;
            NSLog(@"分区经理");
            
        }else if (btn.tag == 103){
            saleVc.leftTitle = @"本日";
            saleVc.rightTitle = @"本月";
            saleVc.headerViewType = 2;
            NSLog(@"大区经理");
            
        }else if (btn.tag == 104){
            saleVc.leftTitle = @"本日";
            saleVc.rightTitle = @"本月";
            saleVc.headerViewType = 5;
            NSLog(@"售后分区经理");
        }
//        else if (btn.tag == 105){
//            saleVc.leftTitle = @"本日";
//            saleVc.rightTitle = @"本月";
//            saleVc.headerViewType = 6;
//            NSLog(@"售后大区经理");
//        }
        else{
            
        }
        [self.navigationController pushViewController:saleVc animated:NO];
        
    }
    
    
}
-(void)viewWillAppear:(BOOL)animated{
    my_AppDelegate.isLandscape = NO;
    NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
    NSLog(@"orientationUnknown==%@",orientationUnknown);
    [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];

    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    NSLog(@"orientationTarget==%@",orientationTarget);
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    self.navigationController.navigationBar.hidden = YES;
    
    if (my_AppDelegate.isyididenglu==2) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"backToLogin" object:nil];
    }
}
-(void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
}
//是否可以旋转
-(BOOL)shouldAutorotate
{
    return NO;
}

//设置是否隐藏
- (BOOL)prefersStatusBarHidden {
    return NO;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
